const { defineConfig } = require("@vue/cli-service");
const path = require("path");
const resolve = (dir) => path.join(__dirname, dir);
const LOCAL_DEV = process.env.VUE_APP_MODEL === "local";
const mock = require("./mock");

module.exports = defineConfig({
  transpileDependencies: true,
  publicPath: process.env.VUE_APP_ROUTER_BASE,
  outputDir: process.env.OUTPUT_DIR, // 'dist', 生产环境构建文件的目录
  assetsDir: "assets_res", // 相对于outputDir的静态资源(js、css、img、fonts)目录
  lintOnSave: LOCAL_DEV, // 是否在开发环境下通过 eslint-loader 在每次保存时 lint 代码
  // 生产模式生成sourcemap
  productionSourceMap: false,
  css: {
    sourceMap: false,
  },
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    name: "",
    resolve: {
      alias: {
        "@/": resolve("src"),
      },
    },
  },
  devServer: {
    port: 8080,
    host: "0.0.0.0",
    https: false,
    compress: false,
    client: {
      overlay: false,
    },
    headers: {
      "X-Custom-Foo": "bar",
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
      "Access-Control-Allow-Headers":
        "X-Requested-With, content-type, Authorization",
    },
    proxy: {
      [process.env.VUE_APP_API_BASE_URL]: {
        target: "http://172.20.10.13:8289/", // 秦
        changeOrigin: true,
        // 用于将/api从请求路径中移除
        pathRewrite: {
          "^/manage/api/tcc": "",
        },
      },
    },
    // before(app) {
    //   if (process.env.VUE_APP_MOCK === "true") {
    //     // 是否开启MOCK，默认开启，检查项目根目录下是否存在.env.development文件 内容为VUE_APP_MOCK=true
    //     // 设置mock数据路由, 创建get或者post目录，该目录下的文件则为url请求地址
    //     // app对象、请求方法、url前缀
    //     // mock.setMock(app, 'get', process.env.VUE_APP_API_BASE_URL);
    //     // app对象、请求方法、url前缀 eg: user_bulk__delete.json => /api/user/bulk_delete
    //     // mock.setMock(app, 'post', process.env.VUE_APP_API_BASE_URL);
    //     // mock.mockSubDirs(app, ['post'], '/abc') // 增加子目录，mock/xxx/post 目录下的文件为url请求地址  eg: user_bulk__delete.json => /xxx/abc/user/bulk_delete
    //     // 设置mock数据路由, 对应目录下，创建get或者post目录，再请求目录下创建业务目录demo(没有层级层级的限制)，该目录下的文件则为url请求地址 eg: fail.json => /demo/fail
    //     // app对象、请求方法、url前缀
    //     mock.setMockByBasePath(app, "get", process.env.VUE_APP_API_BASE_URL);
    //     mock.setMockByBasePath(app, "post", process.env.VUE_APP_API_BASE_URL);
    //   }
    // },
  },
});
